package system

import (
	systemHandler "server/handler/v1/system"
	"server/model"
	"server/repo"
	systemService "server/service/v1/system"
)

type HandlerApp struct {
	CaptchaHandler  systemHandler.CaptchaHandler
	UserHandler     systemHandler.UserHandler
	RoleHandler     systemHandler.RoleHandler
	MenuHandler     systemHandler.MenuHandler
	UserRolrHandler systemHandler.UserRoleHandler
	RoleMenuHandler systemHandler.RoleMenuHandler
}

func NewHandlerApp() *HandlerApp {
	captchaService := systemService.NewCaptchaServiceApp()

	userRepo := repo.NewRepositoryApp[model.User]()
	roleRepo := repo.NewRepositoryApp[model.Role]()
	menuRepo := repo.NewRepositoryApp[model.Menu]()
	userRoleRepo := repo.NewRepositoryApp[model.UserRole]()
	roleMenuRepo := repo.NewRepositoryApp[model.RoleMenu]()

	userService := systemService.NewUserServiceApp(userRepo, menuRepo, userRoleRepo, roleMenuRepo)
	roleService := systemService.NewRoleServiceApp(roleRepo)
	menuService := systemService.NewMenuServiceApp(menuRepo)
	userRoleService := systemService.NewUserRoleServiceApp(userRepo, roleRepo, userRoleRepo)
	roleMenuService := systemService.NewRoleMenuServiceApp(roleRepo, menuRepo, roleMenuRepo)

	return &HandlerApp{
		CaptchaHandler:  *systemHandler.NewCaptchaHandlerApp(captchaService),
		UserHandler:     *systemHandler.NewUserHandlerApp(userService),
		RoleHandler:     *systemHandler.NewRoleHandlerApp(roleService),
		MenuHandler:     *systemHandler.NewMenuHandlerApp(menuService),
		UserRolrHandler: *systemHandler.NewUserRoleHandlerApp(userRoleService),
		RoleMenuHandler: *systemHandler.NewRoleMenuHandlerApp(roleMenuService),
	}
}
